package com.squareup.picasso;

import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;

import com.squareup.picasso.Picasso.LoadedFrom;

import java.util.List;

final class DispatcherHandler extends Handler {
    DispatcherHandler(Looper arg1) {
        super(arg1);
    }

    public final void handleMessage(Message arg15) {
        Object v1;
        Exception v3 = null;
        switch (arg15.what) {
            case 3: {
                ((Action) arg15.obj).picasso.cancelRequest(((Action) arg15.obj).getTarget());
                return;
            }
            case 8: {
                Object v0 = arg15.obj;
                int v7 = ((List) v0).size();
                int v6;
                for (v6 = 0; true; ++v6) {
                    if (v6 >= v7) {
                        return;
                    }

                    v1 = ((List) v0).get(v6);
                    Picasso v8 = ((BitmapHunter) v1).picasso;
                    Action v9 = ((BitmapHunter) v1).action;
                    List<Action> v10 = ((BitmapHunter) v1).actions;
                    int v3_1 = v10 == null || (v10.isEmpty()) ? 0 : 1;
                    int v2 = v9 != null || v3_1 != 0 ? 1 : 0;
                    if (v2 != 0) {
                        Drawable v11 = ((BitmapHunter) v1).result;
                        LoadedFrom v12 = ((BitmapHunter) v1).loadedFrom;
                        if (v9 != null) {
                            v8.complete(v11, v12, v9, ((BitmapHunter) v1).exception);
                        }

                        if (v3_1 == 0) {
                            continue;
                        }

                        int v9_1 = v10.size();
                        for (v3_1 = 0; v3_1 < v9_1; ++v3_1) {
                            v8.complete(v11, v12, v10.get(v3_1), ((BitmapHunter) v1).exception);
                        }
                    }
                }
            }
            case 13: {
                List v0 = (List) arg15.obj;
                int v6 = ((List) v0).size();
                int v4;
                for (v4 = 0; v4 < v6; ++v4) {
                    v1 = ((List) v0).get(v4);
                    Picasso v7_1 = ((Action) v1).picasso;
                    Bitmap v2_1 = MemoryPolicy.shouldReadFromMemoryCache(0) ? v7_1.quickMemoryCacheCheck(((Action) v1).key) : ((Bitmap) null);
                    if (v2_1 != null) {
                        v7_1.complete(new BitmapDrawable(v7_1.context.getResources(), v2_1), LoadedFrom.MEMORY, ((Action) v1), v3);
                    } else {
                        v7_1.submit(((Action) v1));
                    }
                }
            }
        }

        throw new AssertionError("Unknown handler message received: " + arg15.what);
    }
}

